package com.resource.map
{
	import flash.utils.ByteArray;

	public class MapDecoder
	{
		public function MapDecoder()
		{
		}
		
		public static function decode(data:ByteArray):Object{
			data.uncompress();
			var res:Object = {};
			res.mapWidth = data.readInt();
			res.mapHeight = data.readInt();
			res.stepWidth = data.readInt();
			res.stepHeight = data.readInt();
			res.tileWidth = data.readInt();
			res.tileHeight = data.readInt();
			
			res.backList = [];
			var n:int = data.readInt();
			while(n > 0){
				var obj:Object = {};
				obj.x = data.readInt();
				obj.y = data.readInt();
				obj.url = data.readUTF();
				res.backList.push(obj);
				n--;
			}
			
			res.frontList = [];
			n = data.readInt();
			while(n > 0){
				var obj:Object = {};
				obj.x = data.readInt();
				obj.y = data.readInt();
				obj.width = data.readInt();
				obj.height = data.readInt();
				obj.url = data.readUTF();
				res.frontList.push(obj);
				n--;
			}
			
			var walkableData:ByteArray = new ByteArray;
			data.readBytes(walkableData, 0, data.bytesAvailable);
			
			res.walkableData = walkableData;
			
			return res;
		}
	}
}